------------------------------------------------------------------------------------------------------------------------------------
      name:  plog_900
       log:  /accounts/projects/jr_ra/GRscarring/erratum/programs/analysis/simulation.log
  log type:  text
 opened on:  27 Nov 2024, 18:04:13

. 
. 
. // Program to simulate the effect of a transitory increase in the unemployment rate,
. // through various channels
. 
. set more off

. eststo clear

. clear

. cap project, doinfo

. if _rc==0 {
.         local pdir "`r(pdir)'"                                                      // the project's main dir.
.         local dofile "`r(dofile)'"                                                  // do-file's stub name
.         local sig {bind:{hi:[`dofile'.dta. RP : `dofile'.do, `c(current_date)']}}       // a signature in notes
.         local doasproject=1
. }

. else {
.         local pdir "~/GRscarring"
.         local dofile "simulation"
.         local doasproject=0
. }

. 
. set more off

. local rootdir "`pdir'"

. local thisdir "`pdir'"

. 
. local scratch "`pdir'/scratch"

. local rawdata "`pdir'/rawdata"

. local output "`pdir'/results"

. 
. if `doasproject'==1 {
.         project, uses(`scratch'/runatc_coeffs.dta)
project GRscar_erratum > do-file uses: "/scratch/public/jr_ra/GRscarring2024/erratum/scratch/runatc_coeffs.dta" filesig(1418047973:1
> 958395)
.         project, uses(`output'/cohfxregs_cyclecoeffs.dta)
project GRscar_erratum > do-file uses: "results/cohfxregs_cyclecoeffs.dta" filesig(1954259473:11299)
. }

.   
. // Set up panel
.  drop _all

.  set obs 50
Number of observations (_N) was 0, now 50.

.  gen cohort=_n

.  sort cohort

.  expand 19
(900 observations created)

.  sort cohort

.  by cohort: gen age=21+_n

.  su age, meanonly

.  assert r(max)==40 & r(min)==22 

.  gen year = cohort + age - 22

.  
.  su cohort if year==21

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
      cohort |         19          12    5.627314          3         21

.  assert r(N)==19

.  tempfile basepanel

.  save `basepanel'
file /tmp/St2868349.000004 saved as .dta format

.  
.  cap program drop simshock

.  program define simshock
  1.    syntax, panel(string) coefficientdata(string) cyclicalitydata(string) model(string) depvar(string)
  2.    // Read in coefficient estimates - theta and phi
.    use "`coefficientdata'", clear
  3.    keep if model=="`model'" & depvar=="`depvar'"
  4.    sort ivartype cvname fvval
  5.    count if ivartype=="Interaction" & cvname=="ur_st"
  6.    if r(N)>0 {
  7.      mkmat fvval b if ivartype=="Interaction" & cvname=="ur_st", matrix(theta)
  8.    }
  9.    else matrix theta=(0, 0 \ 2, 0 \ 4, 0 \ 6, 0 \ 8, 0)
 10.    count if ivartype=="Interaction" & cvname=="ur0"
 11.    if r(N)>0 {
 12.      mkmat fvval b if ivartype=="Interaction" & cvname=="ur0", matrix(phi)
 13.    }
 14.    else matrix phi=(0, 0 \ 2, 0 \ 4, 0 \ 6, 0 \ 8, 0)
 15.    
.    matrix list theta
 16.    matrix list phi
 17.    forvalues i=0/4 {
 18.      local phi`i'=el(phi,`i',2)*100
 19.      local theta`i'=el(theta,`i', 2)*100
 20.      di "Phi`i' is `phi`i''. Theta`i' is `theta`i''"
 21.    }
 22.    // Read in cyclicality coefficients
.    use "`cyclicalitydata'", clear
 23.    keep if model=="`model'" & depvar=="`depvar'"
 24.    keep if samp=="preGR" & controls=="trend"
 25.    su beta, meanonly
 26.    assert r(N)==1
 27.    local cyclic_time=r(mean)
 28.    su delta, meanonly
 29.    assert r(N)
 30.    local cyclic_cohort=r(mean)
 31. 
.    // Model effects of a shock in year 21
.    use `panel', clear
 32.    local shockyear=21
 33.    gen cohorteffects=0
 34.    gen timeeffects=0
 35.    gen scarring=0
 36.    gen sensitivity=0
 37.    replace cohorteffects = cohorteffects+(`cyclic_cohort') if cohort==`shockyear'
 38.    replace timeeffects=timeeffects+(`cyclic_time') if year==`shockyear'
 39.    replace scarring=scarring+`phi0' if cohort==`shockyear' & inlist(age, 22, 23)
 40.    replace scarring=scarring+`phi1' if cohort==`shockyear' & inlist(age, 24, 25)
 41.    replace scarring=scarring+`phi2' if cohort==`shockyear' & inlist(age, 26, 27)
 42.    replace scarring=scarring+`phi3' if cohort==`shockyear' & inlist(age, 28, 29)
 43.    replace scarring=scarring+`phi4' if cohort==`shockyear' & inlist(age, 30, 31)
 44.    replace sensitivity=sensitivity+`theta0' if year==`shockyear' & inlist(age, 22, 23)
 45.    replace sensitivity=sensitivity+`theta1' if year==`shockyear' & inlist(age, 24, 25)
 46.    replace sensitivity=sensitivity+`theta2' if year==`shockyear' & inlist(age, 26, 27)
 47.    replace sensitivity=sensitivity+`theta3' if year==`shockyear' & inlist(age, 28, 29)
 48.    replace sensitivity=sensitivity+`theta4' if year==`shockyear' & inlist(age, 30, 31)
 49. 
.    // Now illustrate results
.    collapse (sum) cohorteffects timeeffects scarring sensitivity, by(year)
 50.    collapse (sum) cohorteffects timeeffects scarring sensitivity
 51.    gen model="`model'"
 52.    gen depvar="`depvar'"
 53.  end 

. 
.  foreach depvar in empl rw_l {
  2.    foreach mod in B C D E {
  3.      tempfile mod`mod'_`depvar'
  4.      simshock, panel("`basepanel'") coefficientdata("`scratch'/runatc_coeffs.dta") ///
>                cyclicalitydata("`output'/cohfxregs_cyclecoeffs.dta") ///
>                model("m`mod'1b") depvar("`depvar'")
  5.      save `mod`mod'_`depvar''             
  6.    }              
  7.  }
(20,597 observations deleted)
  0
  0

theta[5,2]
    c1  c2
r1   0   0
r2   2   0
r3   4   0
r4   6   0
r5   8   0

phi[5,2]
    c1  c2
r1   0   0
r2   2   0
r3   4   0
r4   6   0
r5   8   0
Phi0 is .. Theta0 is .
Phi1 is 0. Theta1 is 0
Phi2 is 0. Theta2 is 0
Phi3 is 0. Theta3 is 0
Phi4 is 0. Theta4 is 0
(132 observations deleted)
(14 observations deleted)
(19 real changes made)
(19 real changes made)
(2 real changes made, 2 to missing)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(2 real changes made, 2 to missing)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
file /tmp/St2868349.000005 saved as .dta format
(20,591 observations deleted)
  5
  0

theta[5,2]
         fvval           b
r1           0  -.00737424
r2           2  -.00479775
r3           4  -.00348028
r4           6  -.00326984
r5           8  -.00293044

phi[5,2]
    c1  c2
r1   0   0
r2   2   0
r3   4   0
r4   6   0
r5   8   0
Phi0 is .. Theta0 is .
Phi1 is 0. Theta1 is -.7374240085482597
Phi2 is 0. Theta2 is -.4797753412276506
Phi3 is 0. Theta3 is -.3480282379314303
Phi4 is 0. Theta4 is -.3269842127338052
(132 observations deleted)
(14 observations deleted)
(19 real changes made)
(19 real changes made)
(2 real changes made, 2 to missing)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(2 real changes made, 2 to missing)
(2 real changes made)
(2 real changes made)
(2 real changes made)
(2 real changes made)
file /tmp/St2868349.000006 saved as .dta format
(20,591 observations deleted)
  0
  5

theta[5,2]
    c1  c2
r1   0   0
r2   2   0
r3   4   0
r4   6   0
r5   8   0

phi[5,2]
         fvval           b
r1           0  -.00687935
r2           2  -.00470733
r3           4  -.00191524
r4           6   .00064522
r5           8  -.00062408
Phi0 is .. Theta0 is .
Phi1 is -.6879348307847977. Theta1 is 0
Phi2 is -.4707326646894217. Theta2 is 0
Phi3 is -.1915242290124297. Theta3 is 0
Phi4 is .064521556487307. Theta4 is 0
(132 observations deleted)
(14 observations deleted)
(19 real changes made)
(19 real changes made)
(2 real changes made, 2 to missing)
(2 real changes made)
(2 real changes made)
(2 real changes made)
(2 real changes made)
(2 real changes made, 2 to missing)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
file /tmp/St2868349.000007 saved as .dta format
(20,585 observations deleted)
  5
  5

theta[5,2]
         fvval           b
r1           0   -.0075186
r2           2  -.00353062
r3           4  -.00319377
r4           6  -.00309959
r5           8  -.00291355

phi[5,2]
         fvval           b
r1           0   .00031022
r2           2  -.00229191
r3           4  -.00082711
r4           6   .00116615
r5           8  -.00037606
Phi0 is .. Theta0 is .
Phi1 is .0310218660160899. Theta1 is -.7518598344177008
Phi2 is -.2291909651830792. Theta2 is -.3530620597302914
Phi3 is -.0827105774078518. Theta3 is -.3193770069628954
Phi4 is .1166147761978209. Theta4 is -.3099587978795171
(132 observations deleted)
(14 observations deleted)
(19 real changes made)
(19 real changes made)
(2 real changes made, 2 to missing)
(2 real changes made)
(2 real changes made)
(2 real changes made)
(2 real changes made)
(2 real changes made, 2 to missing)
(2 real changes made)
(2 real changes made)
(2 real changes made)
(2 real changes made)
file /tmp/St2868349.000008 saved as .dta format
(20,597 observations deleted)
  0
  0

theta[5,2]
    c1  c2
r1   0   0
r2   2   0
r3   4   0
r4   6   0
r5   8   0

phi[5,2]
    c1  c2
r1   0   0
r2   2   0
r3   4   0
r4   6   0
r5   8   0
Phi0 is .. Theta0 is .
Phi1 is 0. Theta1 is 0
Phi2 is 0. Theta2 is 0
Phi3 is 0. Theta3 is 0
Phi4 is 0. Theta4 is 0
(132 observations deleted)
(14 observations deleted)
(19 real changes made)
(19 real changes made)
(2 real changes made, 2 to missing)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(2 real changes made, 2 to missing)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
file /tmp/St2868349.000009 saved as .dta format
(20,591 observations deleted)
  5
  0

theta[5,2]
         fvval           b
r1           0  -.00812006
r2           2  -.00534585
r3           4  -.00537183
r4           6   -.0022277
r5           8  -.00114264

phi[5,2]
    c1  c2
r1   0   0
r2   2   0
r3   4   0
r4   6   0
r5   8   0
Phi0 is .. Theta0 is .
Phi1 is 0. Theta1 is -.8120056241750717
Phi2 is 0. Theta2 is -.5345848854631186
Phi3 is 0. Theta3 is -.5371826700866222
Phi4 is 0. Theta4 is -.2227699849754572
(132 observations deleted)
(14 observations deleted)
(19 real changes made)
(19 real changes made)
(2 real changes made, 2 to missing)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(2 real changes made, 2 to missing)
(2 real changes made)
(2 real changes made)
(2 real changes made)
(2 real changes made)
file /tmp/St2868349.00000a saved as .dta format
(20,591 observations deleted)
  0
  5

theta[5,2]
    c1  c2
r1   0   0
r2   2   0
r3   4   0
r4   6   0
r5   8   0

phi[5,2]
         fvval           b
r1           0  -.01118381
r2           2  -.01025442
r3           4   -.0037837
r4           6  -.00400707
r5           8  -.00147048
Phi0 is .. Theta0 is .
Phi1 is -1.118381414562464. Theta1 is 0
Phi2 is -1.025441661477089. Theta2 is 0
Phi3 is -.3783703781664371. Theta3 is 0
Phi4 is -.4007068462669849. Theta4 is 0
(132 observations deleted)
(14 observations deleted)
(19 real changes made)
(19 real changes made)
(2 real changes made, 2 to missing)
(2 real changes made)
(2 real changes made)
(2 real changes made)
(2 real changes made)
(2 real changes made, 2 to missing)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
file /tmp/St2868349.00000b saved as .dta format
(20,585 observations deleted)
  5
  5

theta[5,2]
         fvval           b
r1           0    .0030845
r2           2   -.0008515
r3           4  -.00414577
r4           6  -.00136114
r5           8  -.00063518

phi[5,2]
         fvval           b
r1           0  -.01393726
r2           2  -.00961711
r3           4  -.00309213
r4           6  -.00373141
r5           8  -.00129978
Phi0 is .. Theta0 is .
Phi1 is -1.393726281821728. Theta1 is .3084502881392837
Phi2 is -.9617111645638943. Theta2 is -.0851498218253255
Phi3 is -.3092131111770868. Theta3 is -.4145767074078321
Phi4 is -.3731411183252931. Theta4 is -.1361138536594808
(132 observations deleted)
(14 observations deleted)
(19 real changes made)
(19 real changes made)
(2 real changes made, 2 to missing)
(2 real changes made)
(2 real changes made)
(2 real changes made)
(2 real changes made)
(2 real changes made, 2 to missing)
(2 real changes made)
(2 real changes made)
(2 real changes made)
(2 real changes made)
file /tmp/St2868349.00000c saved as .dta format

.  use `modB_empl'

.  append using `modC_empl' `modD_empl' `modE_empl' `modB_rw_l' `modC_rw_l' `modD_rw_l' `modE_rw_l'

.  outsheet using `output'/`dofile'.csv, replace comma

.  
. if `doasproject'==1 {
.         project, creates(`output'/`dofile'.csv)
project GRscar_erratum > do-file creates: "results/simulation.csv" filesig(588680282:446)
. }

.             
. 
end of do-file
      name:  plog_900
       log:  /accounts/projects/jr_ra/GRscarring/erratum/programs/analysis/simulation.log
  log type:  text
 closed on:  27 Nov 2024, 18:04:13
------------------------------------------------------------------------------------------------------------------------------------
